#!/bin/bash -e

function info() {
echo Usage: `basename $0` [-e err_rate -m min_len] reads1.fq[.gz] reads2.fq[.gz]
exit 2
}


while getopts  ":e:m:p:" opts
do
        case  $opts  in
		e) err_rate=$OPTARG;;
        m) min_len=$OPTARG;;
		p) out_prefix=$OPTARG;;
		*) info;;
        esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then info; fi
if [ -z "$min_len" ]; then min_len=30; fi
if [ -z "$err_rate" ]; then err_rate=0.16; fi

. $var

# cutadapt=$tools_path/py_module/bin/cutadapt


# cutadp_170214.sh -p${out_prefix}_tmp $@


quality=20
overlap=1
cut_repeat=2
# overlap=1 # prefer to discard
# err_rate=0.2 # prefer to discard

primer5maltic20=GTGAGTGATGGTTGAGGTAG
primer3maltic20=CTCCACACTACCTCAACCAT

n5=NNNNN
n8=NNNNNNNN
k3=KKK # gt
m3=MMM # ac
malbac5_13=ATGGTTGAGGTAG${n5}${k3}
malbac3_13=${m3}${n5}CTCCACACTACCT

malbac5_10=GTTGAGGTAG${n8}
malbac3_10=${n8}CTCCACACTA


# ${tools_path}/Python-2.7.10/python \
# $
cutadapt \
-q $quality \
--overlap $overlap \
-e $err_rate \
-n $cut_repeat \
-m $min_len \
-a $malbac3_10 \
-A $malbac3_10 \
-g $malbac5_10 \
-G $malbac5_10 \
-o $out_prefix.1.cut.fastq \
-p $out_prefix.2.cut.fastq \
$@


. $cmd_done
